<?php
/**
 * Author: 命中水、
 * Date: 2020/5/17 18:28
 * Email: in1993summer@163.com
 */

namespace App\Console\Commands\Demand;

use App\Repositories\Demand\DemandRepository;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

/**
 * Class ClearTop
 * @package App\Console\Commands\Demand
 */
class ClearTop extends Command
{

    protected $signature = 'demand:clearTop';

    protected $description = 'clear top demand';

    private $demandRepository;

    private $logger;

    /**
     * ClearTop constructor.
     * @param DemandRepository $demandRepository
     */
    public function __construct(DemandRepository $demandRepository)
    {
        parent::__construct();

        $this->demandRepository = $demandRepository;

        $this->logger = Log::channel('console');
    }

    /**
     * @throws \Exception
     */
    public function handle()
    {
        try {

            $this->demandRepository->clearTopDemand();

        } catch (\Exception $e) {

            $this->logger->error($this->signature, [$e]);

            $this->error($e->getMessage());
        }

        $this->info($this->signature . ' success！'. (new Carbon())->toDateTimeString());
    }
}